#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define maxSize 10
typedef struct SeqQueue
{
	int data[maxSize];
	int length;
	int front;
	int rear;
}Queue,*SeqQueue;
void Init(SeqQueue *Q){
	*Q =(SeqQueue) malloc(sizeof(Queue));
	(*Q)->rear = maxSize - 1;
	(*Q)->front = 0;
	(*Q)->length = 0;
}
bool IsEmpty(SeqQueue Q){
	if((Q->rear + 1) % maxSize == Q->front){
		return true;
	}
	return false;
}
bool isFull(SeqQueue Q){
	if((Q->rear + 1) == Q->front){
		return true;
	}
	return false;
}
void Enqueue(SeqQueue *Q,int data){
	if(isFull(*Q)){
		printf("队列已满\n");
		return;
	}
	(*Q)->rear = ((*Q)->rear + 1) % maxSize;
	(*Q)->data[(*Q)->rear] = data;
	(*Q)->length++;
}
void Dequeue(SeqQueue *Q,int *data){
	if(IsEmpty(*Q)){
		printf("队列已空");
		return;
	}
	(*Q)->front = ((*Q)->front + 1) % maxSize;
	*data  = (*Q)->data[(*Q)->rear];
	(*Q)->length--;
}
void OutputQueue(SeqQueue Q){
	for(int i=0;i<Q->length+1;i++){
		printf("%d\n",Q->data[i]);
	}
}
int main(int argc, char *argv[]) {
	SeqQueue Q;
	Init(&Q);
	int choose,data;
	while (1) {
		printf("1.入队 2.出队 3.输出队列\n");
		printf("请输入你的选择:");
		scanf("%d",&choose);
		if(choose == 1){
			int a;
			printf("请输入你要入队的数据:");
			scanf("%d",&a);
			Enqueue(&Q, a);
		}
		else if (choose == 2) {
			Dequeue(&Q, &data);
			//printf("%d\n",data);
		}
		else if (choose == 3) {
			OutputQueue(Q);
		}
	}
}